// login.js
const loginDao = require('../dao/search');
const util = require('../utilitys');
/**
 * 后台登录接口业务逻辑
 * @param ctx
 * @returns {Promise<boolean>}
 * @constructor
 */
exports.getlogin = async (ctx) => {
  console.log(ctx);
  let phone = ctx.request.body.phone || '';
  let psd = ctx.request.body.password || '';
  if (!phone || !psd) {
    ctx.body = util.resultErrorJson(undefined, '手机号码或密码不能为空', {});
    return false;
  }
  try {
    let result = await loginDao.adminLogin(ctx, { phone, psd });
    if (result.length > 0) {
      ctx.body = util.resultSuccessJson(undefined, undefined, result);
    } else {
      ctx.body = util.resultSuccessJson(undefined, '账号或密码错误', {});
    }
  } catch (err) {
    ctx.body = util.resultErrorJson(undefined, err, {});
  }
};
